home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d979.lha / SnoopLibs / fd2sl / fd2sl.c < prev   
C/C++ Source or Header  |  1980-01-11  |  5KB  |  169 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <clib/exec_protos.h>
  5. #include <clib/dos_protos.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <dos/stdio.h>
  9. #include <stdlib.h>
  10. #include <libraries/dos.h>
  11.  
  12. //-------------------------------------------------------------------------\\
  13. //--- fd2sl -> convert library ".fd" files to SnoopLibs's ".sl" files.  ---\\
  14. //--- Compile: (SAS 5.x)  lc -v -cfuist -L fd2sl.c                      ---\\
  15. //---                                                                   ---\\
  16. //--- The format of the ".sl" files is in ascii so the output-format    ---\\
  17. //--- strings can be edited; this will make a better output possible.   ---\\
  18. //---                                                                   ---\\
  19. //--- (c) ASWare 1993  by Ekke Verheul.                                 ---\\
  20. //--- ASWare, Postbus 2521, 3000 CM, Rotterdam, the Netherlands.        ---\\
  21. //-------------------------------------------------------------------------\\
  22.  
  23. LONG line   = 0;
  24. WORD offset = 0;
  25. BOOL public = 1, remarks = 1;
  26. UBYTE name[64], args[128], format[256];
  27.  
  28. int Convert( UBYTE *buf );
  29. void PrintFunction( UBYTE *buf );
  30.  
  31. //-----------------------------------------------------------------
  32. void main(int argc, char **argv)
  33. {
  34. FILE *input;
  35. UBYTE buf[256];
  36.  
  37.     if (argc > 1 && argv[1][0] != '?')
  38.     {
  39.         if (input = fopen(argv[1],"r"))
  40.         {
  41.             if (argc > 2 && argv[2][0] == 'R') remarks = 0;
  42.  
  43.             while (fgets(buf,256,input))
  44.             {
  45.                 if (Convert(buf)) break;
  46.                 line++;
  47.             }
  48.             fclose(input);
  49.         }
  50.     }
  51.     else
  52.     {   printf ("\nFORMAT: fd2sl [>output.sl] <name.fd> [R]\n\n");
  53.     }
  54. }
  55.  
  56. //-----------------------------------------------------------------
  57. int Convert( UBYTE *buf )
  58. {
  59.     switch (line)
  60.     {
  61.         case 0:   //--- the first line must be a `* "#?.library"'
  62.         {   UBYTE *ptr;
  63.  
  64.             if (!strncmp(buf,"* \"",3))
  65.             {
  66.                 for (ptr=&buf[3]; *ptr && *ptr != '.'; ptr++);
  67.  
  68.                 if (*ptr)
  69.                 {   *ptr++ = '\0';
  70.                     if (!strncmp(ptr,"library\"",8))
  71.                     {
  72.                         printf("* SnoopLib: %s.library\n",&buf[3]);
  73.                         return(0);
  74.                     }
  75.                 }
  76.             }
  77.             printf("Not a library.fd file...\n");
  78.             return(-1);
  79.         }
  80.         case 1:
  81.         {   if (!strncmp(buf,"##base ",7)) return(0);
  82.             return(1);
  83.         }
  84.         default:
  85.         {
  86.             switch (buf[0])
  87.             {
  88.                 case '*':
  89.                 {   if (remarks) printf(buf);
  90.                     return(0);  //--- skip remarks
  91.                 }
  92.                 case '#':
  93.                 {   int offs;
  94.                     if (sscanf(buf,"##bias %d",&offs))   //--- set offset
  95.                     {   offset = offs;
  96.                         return(0);
  97.                     }
  98.                     else if (!strncmp(buf,"##public",8))
  99.                     {   public = 1;
  100.                         return(0);
  101.                     }
  102.                     else if (!strncmp(buf,"##private",9))
  103.                     {   public = 0;
  104.                         return(0);
  105.                     }
  106.                     else if (!strncmp(buf,"##end",5))
  107.                     {   return(-1);
  108.                     }
  109.                     printf(" Unknown command: %s\n",buf);
  110.                     return(-1);
  111.                 }
  112.                 default:
  113.                 {
  114.                     if (public)
  115.                     {   PrintFunction(buf);
  116.                     }
  117.                     offset += 6;
  118.                     return(0);
  119.                 }
  120.             }
  121.         }
  122.     }
  123. }
  124.  
  125. //-----------------------------------------------------------------
  126. void PrintFunction( UBYTE *buf )
  127. {
  128. UBYTE *ptr1,*ptr2,*p;
  129. WORD i;
  130.  
  131.     name[0] = 0;
  132.     args[0] = 0;
  133.     format[0] = 0;
  134.  
  135.     //--- TextLength(rp,string,count)(a1,a0,d0)
  136.     //--- ==> FFCA TextLength «%s(rp: 0x%06lx, string: 0x%06lx, count: %ld)» «a1,a0,d0»
  137.  
  138.     for (ptr1=buf,i=0; *ptr1 && *ptr1 != '(' && i < 63; name[i++] = *ptr1++); //--- copy name
  139.     name[i] = 0; ptr1++;
  140.  
  141.     strcpy(format,"«%s (");
  142.  
  143.     if (*ptr1!=')') //--- any arguments ?
  144.     {
  145.         strcpy(args,"«");
  146.  
  147.         for (ptr2 = ptr1; *ptr2 && *ptr2 != '('; ptr2++);   //--- find registers
  148.         ptr2++;
  149.         for (p=ptr2; *p; p++) if (*p==',' || *p=='/' || *p==')') *p=0;
  150.  
  151.         for (p=ptr1; p<ptr2; p++) //--- count args
  152.         {   if (*p==',' || *p==')')
  153.             {   *p=0;
  154.                 strcat(format,ptr1);
  155.                 while (*ptr1) ptr1++; ptr1++;
  156.                 if (*ptr2 == 'd') strcat(format,": %ld, ");
  157.                 else strcat(format,": 0x%06lx, ");
  158.                 strcat(args,ptr2);
  159.                 strcat(args,",");
  160.                 while (*ptr2) ptr2++; ptr2++;
  161.             }
  162.         }
  163.         format[strlen(format)-2]='\0';
  164.         args[strlen(args)-1]='»';
  165.     }
  166.     else strcat(format," void ");
  167.     strcat(format,")»");
  168.     printf( "%04X %s %s %s\n",(-offset)&0xFFFF,name,format,args);
  169. }